package com.mayi.zds.provider;

import com.mayi.zds.entity.OrderQueryParam;
import org.apache.ibatis.jdbc.SQL;

/**
 * @ClassName OrderProvider
 * @Author zhong
 * @Date 2019/12/26 00:28:42
 * @Version 1.0
 */
public class OrderProvider {
    public String getListByConditions(OrderQueryParam param){
        return new SQL(){
            {
                SELECT("*").FROM("zds_order");

                if(param.getStartTime()!=null){
                    WHERE("order_time > #{startTime}");
                }
                if(param.getEndTime()!=null){
                    WHERE("order_time < #{endTime}");
                }

                if(param.getUserId()!=null && !param.getUserId().trim().equals("")) {
                    WHERE("user_id=#{userId}");
                }
                if(param.getBusinessId()!=null && !param.getBusinessId().trim().equals("")) {
                    WHERE("business_id=#{businessId}");
                }
                if(param.getRiderId()!=null && !param.getRiderId().trim().equals("")) {
                    WHERE("rider_id=#{riderId}");
                }
                ORDER_BY("order_time desc");
            }
        }.toString();
    }
}
